import tkinter
import tkmacosx
from PIL import Image, ImageTk
import transfile_client


class ShowImg:
    def __init__(self, yun,path):
        self.yun = yun
        self.frame = tkmacosx.SFrame(yun,width=600,height=400)
        self.img1 = Image.open(path)
        self.img2 = ImageTk.PhotoImage(self.img1)
        self.img_label = tkinter.Label(self.frame, image=self.img2)

    def grid(self):
        self.img_label.grid(row=0, column=0)
        self.frame.grid(row=0, column=0)


def create_show(username,friend_username):
    yun = tkinter.Toplevel()
    # 通过TCP获取词频
    ls = ["get_pic", username, friend_username]
    tcp_pic = transfile_client.FileClient(ls)
    tcp_pic.send_request()
    frame = tkmacosx.SFrame(yun, width=600,height=400)
    img1 = Image.open(tcp_pic.rev_pic())
    img2 = ImageTk.PhotoImage(img1)
    img_label = tkinter.Label(frame, image=img2)
    img_label.grid(row=0,column=0)
    frame.pack()
    yun.title("词云展示")
    yun.mainloop()


if __name__ == '__main__':
    create_show("15133854715","17849327316")
    # path = "/Users/sapple/Documents/python_webchat/serverer/1.png"
    # main(path)
